/*
 * date.cpp
 *
 *  Created on: Apr 14, 2009
 *      Author: kuncai
 */
#include "date.h"
Date::Date()
{
	time(&mTime_t);	
	mTm = *(gmtime(&mTime_t));
	sTime = asctime(&mTm);
}
Date::Date( tm Tm)
{
	mTime_t = mktime(&Tm);		
	mTm = Tm;
	sTime = asctime(&mTm);
}
Date::Date( time_t Time_t)
{
	mTime_t = Time_t;
	mTm = *(gmtime(&mTime_t));
	sTime = asctime(&mTm);
}
Date::Date(string Time)
{
	sTime = Time;
	strptime(Time.c_str(),"%a %b %d %H:%M:%S %Y",&mTm);
	mTime_t = mktime(&mTm);
}
string Date::ToString()
{
	if(sTime.at(sTime.length()-1) == '\n'){
		sTime.erase(sTime.length()-1);
	}
	return sTime;
}
time_t Date::ToTime_t()
{
	return mTime_t;
}
int Date::Cmp(Date* date)
{
	return difftime(mTime_t,date->ToTime_t());
}
